Post-merge-review: Fix template-no-action false positive in GJS/GTS#2677
Open
johanrd wants to merge 3 commits intoember-cli:masterfrom
Open
Post-merge-review: Fix template-no-action false positive in GJS/GTS#2677johanrd wants to merge 3 commits intoember-cli:masterfrom
template-no-action false positive in GJS/GTS#2677johanrd wants to merge 3 commits intoember-cli:masterfrom
Conversation
lib/rules/template-no-action.js
Outdated
| } | ||
|
|
||
| return { | ||
| GlimmerBlockStatement(node) { |
Contributor
There was a problem hiding this comment.
we dont need to do this -- scope is already managed by the parser
Contributor
Author
There was a problem hiding this comment.
thanks, fixing that for the others as well, now
NullVoxPopuli
requested changes
Apr 13, 2026
d8426e4 to
d77c61c
Compare
`action` is an ambient strict-mode keyword in Ember (registered in
STRICT_MODE_KEYWORDS at @ember/template-compiler/lib/plugins/index.ts),
so `{{action this.x}}` works in .gjs/.gts templates without an import.
The rule should still flag those uses — its purpose is to discourage
the deprecated keyword everywhere — but skip cases where `action`
resolves to a JS-scope binding or a template block param:
- `import action from './my-action-helper'; {{action this.x}}` (user import)
- `const action = (h) => () => h(); {{action this.x}}` (local declaration)
- `{{#each items as |action|}}{{action this.x}}{{/each}}` (block-param shadow)
- `<Foo as |action|>{{action this.x}}</Foo>` (element-block-param shadow)
Add the same JS-scope-walk + block-param tracking pattern used by
template-no-log, template-no-unbound, etc.: walk
sourceCode.getScope().variables for the JS side, and push/pop
GlimmerBlockStatement.program.blockParams and GlimmerElementNode.blockParams
for template-side scopes. The `@action` and `this.action` head-type checks
are unchanged (those are JS-side namespaces, not the template keyword).
Tests: 22 (was 8) — adds 9 new valid cases (5 JS-scope, 4 block-param) and
5 new invalid cases (3 ambient-keyword in .gjs/.gts, 1 unrelated import
does not mask, 1 ambient-after-block-exit).
Docs updated to document the strict-mode behavior.
d77c61c to
003543c
Compare
|
|
||
| ## Strict-mode behavior | ||
|
|
||
| `action` is an ambient strict-mode keyword in Ember (registered in `STRICT_MODE_KEYWORDS`), so `{{action this.x}}` works in `.gjs`/`.gts` templates without an explicit import. The rule still flags those uses to discourage the deprecated keyword — but skips reports when `action` resolves to a JS-scope binding (an import or local declaration) or a template block param. |
Contributor
There was a problem hiding this comment.
I think it was also removed in ember 6? can you double check that? so for users of ember-source 6+ we could provide a more specific error
Contributor
Author
There was a problem hiding this comment.
added a more specific error now
{{action}} was deprecated in Ember 5.9 and removed in 6.0. Mention
this in all three message variants so users know the timeline without
having to look it up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's broken on
masteractionis an ambient strict-mode keyword in Ember (registered inSTRICT_MODE_KEYWORDSat@ember/template-compiler/lib/plugins/index.ts), so{{action this.x}}works in.gjs/.gtstemplates without an import. The rule correctly flags the ambient keyword in both modes, but it doesn't account for users who legitimately shadowactionwith a JS binding or a template block param:Fix
Add the JS-scope-walk + block-param tracking pattern already established in
template-no-log,template-no-unbound,template-no-restricted-invocations, etc.:sourceCode.getScope().variablesto detect JS bindings namedaction.GlimmerBlockStatement.program.blockParamsandGlimmerElementNode.blockParamsto track template-side block params.actionresolves to a local binding (either source).The existing
@actionandthis.actionhead-type guards are unchanged (those are JS-side namespaces, not the template keyword).Test plan
22 tests pass on the branch (was 8). New cases:
import,const, mustache/sub-expression/modifier positions, both extensions){{#each as |action|}},{{#let as |action|}}, modifier inside block, element-level<Foo as |action|>)import handler from './handler') does NOT mask the ruleactionoutside a block-param scope is still flagged even when a sibling block legitimately shadows itCowritten by claude